#include "RCCamera.h"

RCCamera::RCCamera(void){ }

RCCamera::RCCamera(XMFLOAT3 pos, XMFLOAT3 worldUp, XMVECTOR rot) 
{
	position = pos;
	worldUpVector = worldUp;
	orientation = rot;
}
RCCamera::~RCCamera(void)
{
	
}
XMMATRIX RCCamera::getProjection()
{
	return projection;
}
XMMATRIX RCCamera::getView()
{
	return view;
}
void RCCamera::Update(float time)
{
	XMMATRIX rotMat;

	rotMat = XMMatrixRotationQuaternion(orientation) * XMMatrixTranslation(position.x,position.y,position.z);
	XMVECTOR md = XMMatrixDeterminant(rotMat);	
	view = XMMatrixInverse(&md,rotMat);		

	if(width != (int)pGame->getGraphicsDevice()->getViewPort().Width && height != (int)pGame->getGraphicsDevice()->getViewPort().Height)
		Initialize();
}

void RCCamera::Initialize()
{
	width = pGame->getGraphicsDevice()->getViewPort().Width;
	height = pGame->getGraphicsDevice()->getViewPort().Height;
	projection = XMMatrixPerspectiveFovLH(XM_PI/4.0f,pGame->getGraphicsDevice()->getViewPort().Width/pGame->getGraphicsDevice()->getViewPort().Height,.1f,20000);	
}

void RCCamera::setWorldUp(XMFLOAT3 up)
{
	worldUpVector = up;
}
void RCCamera::setWidth(UINT newWidth)
{
	width = newWidth;
}
void RCCamera::setHeight(UINT newHeight)
{
	height = newHeight;
}

